package com.shuzixiangcun.service.admin;

import com.shuzixiangcun.entity.Villages;
import com.shuzixiangcun.dao.VillagesDao;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;

/**
 * 村庄表(Villages)表服务实现类
 *
 * @author makejava
 * @since 2024-06-24 08:26:17
 */
@Service
public class VillagesServiceImpl {
    @Resource
    private VillagesDao villagesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param villageId 主键
     * @return 实例对象
     */

    public Villages queryById(Integer villageId) {
        return this.villagesDao.queryById(villageId);
    }

    /**
     * 分页查询
     *
     * @param villages    筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */


    /**
     * 新增数据
     *
     * @param villages 实例对象
     * @return 实例对象
     */

    public Villages insert(Villages villages) {
        this.villagesDao.insert(villages);
        return villages;
    }

    /**
     * 修改数据
     *
     * @param villages 实例对象
     * @return 实例对象
     */

    public Villages update(Villages villages) {
        this.villagesDao.update(villages);
        return this.queryById(villages.getVillageId());
    }

    /**
     * 通过主键删除数据
     *
     * @param villageId 主键
     * @return 是否成功
     */

    public boolean deleteById(Integer villageId) {
        return this.villagesDao.deleteById(villageId) > 0;
    }
}
